﻿/// Copyright © 2013 Microsoft Corporation. 
/// This project is released under the Microsoft Public License (MS-PL)
///
namespace DataMorph.Processing
{
    using System;

    using DataMorph.Common.Contracts;

    public class TagDataParser : ITagDataParser
    {
        private static readonly char[] Separators = new[] { ',' };

        public TagData Parse(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return null;
            }

            var parts = str.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length == 3)
            {
                return new TagData
                {
                    TagId = parts[0],
                    Ticks = long.Parse(parts[1]),
                    Value = parts[2]
                };
            }

            return null;
        }
    }
}